<?php
class SysSetBusi {
	//修改系统设置
	public function updateSysSet($condition) {
		global $mysqlTools;
		$condition = $mysqlTools->check_input($condition);
		try {
			$sql = "UPDATE `sys_set` SET ";
			if(!empty($condition['sysBenLoginId'])){
				$queryUserInfoByLoginId = "
					SELECT 
					su.userId, 
					su.userLoginId 
					from sys_user su 
					where su.userLoginId = $condition[sysBenLoginId] 
					LIMIT 0,1
				";
				
				$sql.= "sysBenLoginId = $condition[sysBenLoginId]";
				$userInfo = $mysqlTools->selectSql($queryUserInfoByLoginId)[0];
				//如果有收益人loginId通过loginId查询出userId一定修改
				$sql.= ",sysBenUserId = $userInfo[userId]";
			}
			if(!empty($condition['sysMinWithdMo'])){
				$sql.= ",`sysMinWithdMo` = $condition[sysMinWithdMo]";
			}
			if(!empty($condition['sysBenPer'])){
				$sql.= ",`sysBenPer` = $condition[sysBenPer]";
			}
			$mysqlTools->startTransaction();
			$result = $mysqlTools->executeSql($sql);
			$mysqlTools->commitTransaction();
		} catch (\Exception $e) {
			$mysqlTools->rollback();
		}
		return $result;
	}
	
	//查询配置信息
	public function querySysSet() {
		global $mysqlTools;
		
		$sql = "
			SELECT
				ss.sysBenUserId,
				ss.sysBenLoginId,
				ss.sysMinWithdMo,
				ss.sysBenPer
			FROM
				sys_set ss
			LIMIT 0,1	
		";
		
		$sysSet = $mysqlTools->selectSql($sql)[0];
		return $sysSet;
	}
}

?>